//
//  YWXBaseTabbarButton.m
//  AntFarms
//
//  Created by MuYouDaoLi on 2017/7/26.
//  Copyright © 2017年 MuXi. All rights reserved.
//

#import "YWXBaseTabbarButton.h"

@interface YWXBaseTabbarButton ()

@property (nonatomic, strong) UILabel *tipLabel; /**< 提示文字数量 */

@end

@implementation YWXBaseTabbarButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _tipLabel = [[UILabel alloc] init];
        _tipLabel.hidden = YES;
        _tipLabel.backgroundColor = UIColorFromRGB(0xff6977);
        _tipLabel.textColor = [UIColor whiteColor];
        _tipLabel.font = [UIFont systemFontOfSize:10];
        _tipLabel.textAlignment = NSTextAlignmentCenter;
        [_tipLabel lf_yuanjiao:8.0];
        [self addSubview:_tipLabel];
    }
    return self;
}

- (void)setTag:(NSInteger)tag {
    [super setTag:tag];
}

#pragma mark 设置button内部的image的范围

- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    
    CGFloat imageW = kNumFrom375(22);
//    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = kNumFrom375(21);
    return CGRectMake(kNumFrom375(36), kNumFrom375(9), imageW, imageH);
}

#pragma mark 设置button内部的title的范围

- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleY = contentRect.size.height * 0.6;
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = contentRect.size.height - titleY;
    return CGRectMake(0, titleY, titleW, titleH);
}
- (void)setHighlighted:(BOOL)highlighted{
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).with.offset(4);
        make.top.equalTo(self.mas_top).with.offset(2);
        make.width.height.mas_equalTo(16);
    }];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


@end
